package com.simple.backlist.controller;

import com.simple.backlist.annotation.DoBackList;
import com.simple.backlist.entity.UserInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 功能描述:
 *
 * @author: WuChengXing
 * @create: 2021-12-27 16:25
 **/
@RestController
public class BackListController {

    private Logger logger = LoggerFactory.getLogger(BackListController.class);

    /**
     * 通过：http://localhost:8081/api/queryUserInfo?userId=111
     * 拦截：http://localhost:8081/api/queryUserInfo?userId=1531513
     */
    @DoBackList(method = "backlist", returnJson = "{\"code\":\"1111\",\"info\":\"黑名单用户不允许访问呢！\"}")
    @GetMapping("/api/queryUserInfo")
    public UserInfo queryUserInfo(@RequestParam String userId) {
        logger.info("查询用户信息，userId：{}", userId);
        return new UserInfo("simple:" + userId, 19, "杭州市文新-0000");
    }

    public boolean backlist(String userId) {
        if ("aaa".equals(userId) || "111".equals(userId)) {
            return true;
        }
        return false;
    }

}
